// pages/toExchange/toExchange.js
const app = getApp();
var WxParse = require('../../../wxParse/wxParse.js');
import api from "../../../utils/util.js"
Page({
  /**
   * 页面的初始数据
   */
  data: {
    statusBarHeight: app.globalData.statusBarHeight,
    fullHeight: app.globalData.fullcontain,
    discount: app.globalData.discount,
    navmess: {
      navtitle: "积分活动详情",
      backhide: 0,
      topheight: 1,
    },
    swiperSetting:{
      indicatorDots: true,
      vertical: false,
      autoplay: false,
      interval: 2000,
      duration: 500,
    },
    demolist:[],
    myScore: 0,
  },
  takegoodto: function(e){
    var url = e.currentTarget.dataset.url;
    wx.navigateTo({
      url: url+ "?mess=" +this.data.activityNo,
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this,
        check = app.checkLogin();
    if(check){
      var token = wx.getStorageSync('token');
      this.setData({
        isLogin: check,
        token: token
      })
    }
    console.log("activityNo: ",options.mess,token);
    that.setData({
      activityNo: options.mess
    })
    //会员可用积分
    api.post("/mini/my/account/score",{
      "token": token
    }).then(res =>{
      console.log("会员积分",res)
      that.setData({
        myScore: res.result.score
      })
    }).catch(res=>{
      console.log(res)
    })
    //积分信息
    api.post("/mini/ext/score/info",{
      "activityNo": JSON.parse(options.mess),
      "token": token
    }).then(res => {
      console.log("积分信息",res)
      that.setData({
        demolist: res.result,
        activityNo: res.result.activityNo
      })
      // 富文本解析初始化数据
      WxParse.emojisInit('[]', "../../../wxParse/emojis/", {
        "00": "00.gif",
        "01": "01.gif",
        "02": "02.gif",
        "03": "03.gif",
        "04": "04.gif",
        "05": "05.gif",
        "06": "06.gif",
        "07": "07.gif",
        "08": "08.gif",
        "09": "09.gif",
        "09": "09.gif",
        "10": "10.gif",
        "11": "11.gif",
        "12": "12.gif",
        "13": "13.gif",
        "14": "14.gif",
        "15": "15.gif",
        "16": "16.gif",
        "17": "17.gif",
        "18": "18.gif",
        "19": "19.gif",
      });
      var article = res.result.detail;
      /*** WxParse.wxParse(bindName , type, data, target,imagePadding)
      * 1.bindName绑定的数据名(必填)
      * 2.type可以为html或者md(必填)
      * 3.data为传入的具体数据(必填)
      * 4.target为Page对象,一般为this(必填)
      * 5.imagePadding为当图片自适应是左右的单一padding(默认为0,可选)*/ 
      var temp = WxParse.wxParse('article', 'html', article, that, 5);
    }).catch(res=>{
      console.log(res)
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})